/**
 * @author xh
 */

// 定义 Female 和 Male 共同的接口
interface Human {
    public void eat(); // 吃饭

    public void sleep(); // 睡觉

    public void beat(); // 打豆豆
}

// 创建实现类 Male
class Male implements Human {
    @Override
    public void eat() {
        System.out.println("Male can eat.");
    }

    @Override
    public void sleep() {
        System.out.println("Male can sleep.");
    }

    @Override
    public void beat() {
        System.out.println("Male can beat.");
    }
}

// 创建实现类 Female
class Female implements Human {
    @Override
    public void eat() {
        System.out.println("Female can eat.");
    }

    @Override
    public void sleep() {
        System.out.println("Female can sleep.");
    }

    @Override
    public void beat() {
        System.out.println("Female can beat.");
    }
}

// 创建普通工厂类
class HumanFactory {
    public Human createHuman(String gender) {
        if ("male".equals(gender)) {
            return new Male();
        } else if ("female".equals(gender)) {
            return new Female();
        } else {
            System.out.println("请输入正确的类型！");
            return null;
        }
    }
}

// 多个工厂方法
class HumanFactory1 {
    public Male creatMale() {
        return new Male();
    }

    public Female createFemale() {
        return new Female();
    }
}

// 多个工厂方法
class HumanFactory2 {
    public static Male creatMale() {
        return new Male();
    }

    public static Female createFemale() {
        return new Female();
    }
}

// 工厂测试类
class FactoryTest {
    public static void main(String[] args) {
//        HumanFactory humanFactory = new HumanFactory();
//        Human female = humanFactory.createHuman("female");
//        female.eat();
//        female.sleep();
//        female.beat();

//        HumanFactory1 humanFactory1 = new HumanFactory1();
//        Male male = humanFactory1.creatMale();
//        male.eat();
//        male.sleep();
//        male.sleep();

        Female female = HumanFactory2.createFemale();
        female.eat();
        female.sleep();
        female.beat();
    }
}

